# alg.py - 最大子数组和动态规划实现

class Solution:
    def maxSubArray(self, nums):
        """
        使用Kadane算法计算最大子数组和
        时间复杂度: O(n)
        空间复杂度: O(1)
        """
        if not nums:
            return 0
            
        current_sum = max_sum = nums[0]
        
        for num in nums[1:]:
            # 在当前位置结束的最大子数组和
            current_sum = max(num, current_sum + num)
            # 更新全局最大和
            max_sum = max(max_sum, current_sum)
            
        return max_sum

def read_nums_from_file(filename):
    """从文件读取整数数组"""
    try:
        with open(filename, 'r') as f:
            line = f.readline().strip()
            if not line:
                return []
            return list(map(int, line.split(',')))
    except FileNotFoundError:
        print("错误：文件 {} 不存在".format(filename))
        return []
    except Exception as e:
        print("读取文件错误: {}".format(e))
        return []